package com.andaily.domain.dto.cooking;

import com.andaily.domain.cooking.settlement.CookingSettlement;
import com.andaily.domain.cooking.settlement.SettlementCookingAccount;
import com.andaily.domain.cooking.settlement.UserSettlement;
import com.andaily.domain.dto.AbstractDTO;
import com.andaily.domain.shared.DateUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Shengzhao Li
 */
public class CookingSettlementDto extends AbstractDTO {

    private String totalAmount;
    private String averageAmount;
    private String createTime;

    private List<UserSettlementDto> userSettlementDtoList = new ArrayList<UserSettlementDto>();
    private List<CookingAccountDto> accountDtoList = new ArrayList<CookingAccountDto>();

    public CookingSettlementDto() {
    }

    public CookingSettlementDto(CookingSettlement settlement) {
        this.guid = settlement.guid();
        this.totalAmount = settlement.totalAmount().toString();
        this.averageAmount = settlement.averageAmount().toString();
        this.createTime = DateUtils.toDateText(settlement.createTime());

        List<UserSettlement> userSettlements = settlement.userSettlements();
        for (UserSettlement userSettlement : userSettlements) {
            userSettlementDtoList.add(new UserSettlementDto(userSettlement));
        }

        List<SettlementCookingAccount> accounts = settlement.accounts();
        for (SettlementCookingAccount account : accounts) {
            accountDtoList.add(new CookingAccountDto(account.account()));
        }
    }

    public int getAccountSize() {
        return accountDtoList.size();
    }

    public List<CookingAccountDto> getAccountDtoList() {
        return accountDtoList;
    }

    public String getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(String totalAmount) {
        this.totalAmount = totalAmount;
    }

    public String getAverageAmount() {
        return averageAmount;
    }

    public void setAverageAmount(String averageAmount) {
        this.averageAmount = averageAmount;
    }

    public List<UserSettlementDto> getUserSettlementDtoList() {
        return userSettlementDtoList;
    }

    public void setUserSettlementDtoList(List<UserSettlementDto> userSettlementDtoList) {
        this.userSettlementDtoList = userSettlementDtoList;
    }

    public String getCreateTime() {
        return createTime;
    }

    public static List<CookingSettlementDto> toDtos(List<CookingSettlement> settlements) {
        List<CookingSettlementDto> dtoList = new ArrayList<CookingSettlementDto>(settlements.size());
        for (CookingSettlement settlement : settlements) {
            dtoList.add(new CookingSettlementDto(settlement));
        }
        return dtoList;
    }
}
